package services

import (
	"cas_central_server/models"
	"net/http"

	"github.com/labstack/echo/v4"
)

func fetchDevicesHandler(c echo.Context) error {
	devices, err := models.GetDevices()
	if err != nil {
		return err
	}
	return c.JSON(http.StatusOK, devices)
}

func updateDevicesHandler(c echo.Context) error {
	devices := []*models.DeviceType{}
	if err := c.Bind(&devices); err != nil {
		return badRequest("wrong devices data, error" + err.Error())
	}
	err := models.UpdateDevices(devices)
	if err != nil {
		return err
	}
	return c.JSON(http.StatusOK, "successfully update devices")
}
